package com.algo.pattern.observable.observable;

import com.algo.pattern.observable.model.StockUpdateResult;

import java.util.Observable;

/**
 * 被监听的对象
 */
public class StockUpdateObservable extends Observable {

    private String messageId;

    /**
     * 当被观察者被设置时，通知到观察者
     * @param updateResult
     */
    public void setResult(boolean updateResult) {
        StockUpdateResult stockUpdateResult = new StockUpdateResult();
        stockUpdateResult.setMessageId(messageId);
        stockUpdateResult.setUpdateResult(updateResult);

        this.setChanged();
        this.notifyObservers(stockUpdateResult);
    }

    public void setMessageId(String messageId) {
        this.messageId = messageId;
    }
}
